package bll

import (
	"jgt-oper/src/model"
	"jgt-oper/src/schema"
	"jgt-oper/src/util"
	"time"
)

// RCBll 公共资源分类管理
type RCBll struct {
	RCModel model.IResourceClassification `inject:"IResourceClassification"`
}

// QueryPage 查询分页
func (a *RCBll) QueryPage(param string, pageIndex uint, pageSize uint) (int64, []*schema.ResourceClassification, error) {
	return a.RCModel.QueryPage(param, pageIndex, pageSize)
}

// Create 创建分类
func (a *RCBll) Create(item *schema.ResourceClassification) error {
	item.ID = 0
	item.RecordID = util.UUID()
	item.Created = time.Now().Unix()
	item.Deleted = 0
	return a.RCModel.Create(item)
}

// Get 查询分类
func (a *RCBll) Get(param string) (*schema.ResourceClassification, error) {
	return a.RCModel.Get(param)
}

// Update 更新分类
func (a *RCBll) Update(id string, item *schema.ResourceClassification) error {
	info := util.StructToMap(item)
	delete(info, "id")
	delete(info, "record_id")
	delete(info, "creator")
	delete(info, "created")
	delete(info, "deleted")

	return a.RCModel.Update(id, info)
}

// Delete 删除分类
func (a *RCBll) Delete(param string) error {
	return a.RCModel.Delete(param)
}
